package com.inspur.edp.common.expr;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ExprListJsonDeserializer extends JsonDeserializer<List<Express>> {

    @Override
    public List<Express> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        JsonNode arrayNode = jsonParser.getCodec().readTree(jsonParser);
        if (arrayNode == null) {
            return null;
        }
        List<Express> expresses = new ArrayList<>();
        for (JsonNode jsonNode : arrayNode) {
            Express express = ExpressDeserializerMgr.deserialize(jsonNode);
            expresses.add(express);
        }
        return expresses;
    }
}